<?
	require_once "../../_func/__Global.php";
	require_once "../../_func/__Local.php";
	require_once "../../_func/__MysqlFunc.php";
	require_once "../../_func/_MngFunc.php";
	require_once "../../_func/_CodeFunc.php";
	require_once "../../_func/_Validation.php";
	
	cacheControl(0);
		
	if ( ValidCheck_isSelfRequest($_SERVER['HTTP_REFERER']) ) {
		if ( $mode == 'u' ) {
			//get parameter
			$member_pwd1 	= $param->getString('member_pwd1');
			$member_pwd2 	= $param->getString('member_pwd2');
			$member_hp 		= $param->getString('member_hp');
			$member_grade 	= $param->getString('member_grade');
			$jbnh_seq 		= $param->getString('jbnh_seq');
			$member_delyn 	= $param->getString('member_delyn');
			$mng_jbnh_seq 	= $param->getString('mng_jbnh_seq');

			//check validation
			if (!ValidCheck_isValidPassword($member_pwd1, $member_pwd2)) {
				errMsg($VALIDATE_ERROR_MESSAGE);
			}
			else if (!ValidCheck_isValidPhone($member_hp)) {
				errMsg($VALIDATE_ERROR_MESSAGE);
			}
			else {
				$update_arr = array(
					'member_pwd'			=> $member_pwd1,
					'member_hp'				=> $member_hp,
					'member_grade'			=> $member_grade,
					'jbnh_seq'				=> $jbnh_seq,
					'member_delyn'			=> $member_delyn,
				);
				
				//회원수정
				$result 		= MemberUpdate( $update_arr, $member_seq);
				
				//관리농협 등록
				if( $result )
				{
					//기존 관리농협 삭제
					$result = ManagerDelete($member_id);
					if ( is_array( $mng_jbnh_seq ) ) {
					
						if ( $result ) {
							//관리농협 등록
							foreach( $mng_jbnh_seq as $key => $val )
							{
								$sub_arr = array(
									'member_id'				=> $member_id,
									'jbnh_seq'				=> $val,
								);		
								ManagerInsert($sub_arr);
								unset($sub_arr);
							}
						}
					}
					cacheControl(0);
					ob_clean();
					jsMsg("수정되었습니다.", '/mng/member.html',true);
				}
			}
		}
		else {
			errMsg("비정상적인 접근입니다.");
		}
	} else {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>:: 농협전북지부 ERP시스템 ::</title>
<link href="/css/layout.css" type="text/css" rel="stylesheet" />
<script src="/js/mng.js"></script>
<script type="text/javascript">
	$(document).ready(function() {
		jQuery.validator.setDefaults({
			onkeyup:false,
			onclick:false,
			onfocusout:false,
			showErrors:function(errorMap, errorList){
				$(errorList[0].element).focus();
				alert(errorList[0].message);
			}
		});
		$("#frm").validate({
			rules: {
				member_pwd1:	{required: true, pwdStr:true, rangelengthKr: [4,20], isPWDSame:true},
				member_pwd2:	{required: true, pwdStr:true, rangelengthKr: [4,20], isPWDSame:true},
				member_hp: 		{required: true, hpNum: true, rangelengthKr: [10,11] },
				member_grade: 	{required: true, range: ['1','2','3'] },
				jbnh_seq: 		{required: true, number: true },
				member_delyn: 	{required: true }
			},
			messages: {
				member_pwd1:	{required: "암호를 입력하세요."},
				member_pwd2:	{required: "암호를 입력하세요."},
				member_hp: 		{required: "핸드폰번호를 입력하세요."},
				member_grade: 	{required: "관리자 등급을 선택하세요."},
				jbnh_seq: 		{required: "농협을 선택하세요"},
				member_delyn: 	{required: "사용여부를 선택하세요"}
			},
			success: function(label) {
				$('#sbmtBtn').remove();
			}
		});
	});
</script>
</head>
<body>
<div id="wrap">
	<!-- header start -->
	<? include("../_layout/head.inc"); ?>
	<!-- header end -->

<?
	$member_seq = $param->getString("chkbxNo", $session->getString("userno") );
	
	$row =& GetMemberInfo($member_seq);
	
	if ( $row == null )
		jserror("정보가 없습니다.");

	if ( $row != null  )
	{
		$member_seq			= $row->getString('member_seq');
		$member_id			= $row->getString('member_id');
		$member_pwd			= $row->getString('member_pwd');
		$member_hp			= $row->getString('member_hp');
		$member_grade		= $row->getString('member_grade');
		$jbnh_seq			= $row->getString('jbnh_seq');
		$member_delyn		= $row->getString('member_delyn');
		$arr_jbnh_seq 		= GetMngJBNHArrayList($member_id);
?>	
	
<!-- container start -->
	<div id="container">
	
	<!-- sub menu start -->
	<? include("../_layout/left.inc"); ?>
	<!-- sub menu end -->	

        <div class="code_contents">
        	<div class="subtit">
        		<p class="subtt15"><span>코드관리 > 관리자 계정관리</span></p>
			</div>
            <p class="tableTitle"><span class="b"></span>관리자 계정 수정</p>
			<form name=frm id=frm method="POST" action="<?echo $PHP_SELF?>">
            <table cellpadding="0" cellspacing="1" border="0" class="erpTable rowLeft">
           		<colgroup>
                  <col width="200px" />
                  <col width="*" />
                  </colgroup>
                <tr>
                    <th>ID <span class="basic">*</span></th>
                    <td><label><?echo $member_id?></label></p>
                    </td>
				</tr>
                <tr>
                    <th>비밀번호 <span class="basic"></span></th>
                    <td><input type="password" id="member_pwd1" name="member_pwd1" value="<?echo $member_pwd?>" class="boxinput w100" />
                    	<p class="comment">*패스워드는 최대 20자리까지 가능합니다.</p>
                    </td>
				</tr>
                <tr>
                    <th>비밀번호 확인 <span class="basic"></span></th>
                    <td><input type="password" id="member_pwd2" name="member_pwd2" value="<?echo $member_pwd?>" class="boxinput w100" /></td>
				</tr>
                <tr>
                    <th>휴대폰번호 <span class="basic">*</span></th>
                    <td><input type="text" id="member_hp" name="member_hp" value="<?echo $member_hp?>" class="boxinput w100" />
                    	<p class="comment">*휴대폰 번호는 "-"없이 숫자만 입력해주세요.</p>
                    </td>
				</tr>
                <tr>
                    <th>관리자등급 <span class="basic">*</span></th>
                    <td>
                    	<input type="radio" id="member_grade" name="member_grade" value="1" <? echo ($member_grade == "1") ? "checked" : "" ?> title="전체관리자"/><span class="txt_radio"> 전체관리자</span>
                        <input type="radio" id="member_grade" name="member_grade" value="2" <? echo ($member_grade == "2") ? "checked" : "" ?> title="지역농협관리자"/><span class="txt_radio"> 지역농협관리자</span>
                        <input type="radio" id="member_grade" name="member_grade" value="3" <? echo ($member_grade == "3") ? "checked" : "" ?> title="지역관리자"/><span class="txt_radio"> 지역관리자</span>
                    </td>
				</tr>
                <tr>
                    <th>농협선택 <span class="basic">*</span></th>
                    <td>
 						<?echo GetJBNHOptionList($jbnh_seq) ?>
                    </td>
				</tr>
                <tr>
                    <th>관리농협</th>
                    <td>
                    	<ul style="height:100px; overflow-y:scroll;">
							<?echo  GetMngJBNHCheckboxList($arr_jbnh_seq)?>
                        </ul>
                    </td>
				</tr>
                <tr>
                    <th>관리자 사용 <span class="basic">*</span></th>
                    <td>
                    	<input type="radio" id="member_delyn" name="member_delyn" value="N" <? echo ($member_delyn == "N") ? "checked" : "" ?> title="사용"/><span class="txt_radio"> 사용</span>
                        <input type="radio" id="member_delyn" name="member_delyn" value="Y" <? echo ($member_delyn == "Y") ? "checked" : "" ?>  title="사용안함"/><span class="txt_radio"> 사용안함</span>
                    </td>
				</tr>
            </table>
            <div class="BtnList">
            	<ul>
					<li><input type="submit" id="sbmtBtn" name="sbmtBtn" title="수정" class="btn_modify" value=""/></li>
					<li><input type="button" class="btn_cancel" title="취소" onClick="MNG.fncRtnfunc('rst','member');"/></li>
					<input type="hidden" name="mode" id="mode" value="u"/>
					<input type="hidden" name="member_seq" id="member_seq" value="<?echo $member_seq?>"/>
                </ul>
            </div>
			</form>
        </div>
    </div>   
<?
	}
?>    
	<!-- footer start -->
	<? include("../_layout/footer.inc"); ?>
	<!-- footer end -->
	
</div>
</body>
</html>
<?
	}
?>